﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Ecreate.Web.popedom.userManage
{
    public partial class useronelist : System.Web.UI.Page
    {
        Ecreate.Popedom.Service.IUserService userService = new Ecreate.Popedom.Service.SpringImpl.UserServiceImpl();
        GridHelper helper = new GridHelper();
        protected void Page_Load(object sender, EventArgs e)
        {
            helper.DeleteHandler = new EventHandler(Delete_Handler);

            EventHandler[] array = new EventHandler[5];
            array[2] += new EventHandler(LinkButton_DataBinding);
            array[3] += new EventHandler(LinkButton_Area_DataBinding);
            array[4] += new EventHandler(LinkButton_UseState_DataBinding);
            helper.CrudUrl = "/popedom/userManage/useronecrud.aspx";
            helper.setGridColumn(this.GridView1, "Id,userName,Group.Groupname,Province.AreaName,Id.UseFlag", "主键,用户名称,组名称,省份,状态标识", array);
            IList<Ecreate.Popedom.tSysuser> l = userService.getAllOne();
            this.GridView1.DataSource = l;
            this.GridView1.DataBind();
        }
        private void LinkButton_DataBinding(object sender, EventArgs e)
        {
            Label lb = (Label)sender;
            GridViewRow container = (GridViewRow)lb.NamingContainer;
            Ecreate.Popedom.tSysuser user = (Ecreate.Popedom.tSysuser)container.DataItem;
            lb.Text = user.Group.Groupname;
        }
        private void LinkButton_Area_DataBinding(object sender, EventArgs e)
        {
            Label lb = (Label)sender;
            GridViewRow container = (GridViewRow)lb.NamingContainer;
            Ecreate.Popedom.tSysuser user = (Ecreate.Popedom.tSysuser)container.DataItem;
            lb.Text = user.Province.AreaName;
        }
        private void LinkButton_UseState_DataBinding(object sender, EventArgs e)
        {
            Label lb = (Label)sender;
            GridViewRow container = (GridViewRow)lb.NamingContainer;
            Ecreate.Popedom.tSysuser user = (Ecreate.Popedom.tSysuser)container.DataItem;
            if (user.UseFlag == 1)
            {
                lb.Text = "有效";
            }
            else
            {
                lb.Text = "无效";
            }
        }


        private void Delete_Handler(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            GridViewRow container = (GridViewRow)lb.NamingContainer;
            Ecreate.Popedom.tSysuser user = (Ecreate.Popedom.tSysuser)container.DataItem;
            lb.Text = helper.getDeleteFormatUrl();
            if (user.Group.Adminflag == 1)
            {
                lb.Text = string.Format(lb.Text, user.Id, " return deleteHandler();");
            }
            else
            {
                lb.Text = string.Format(lb.Text, user.Id, "");
            }

        }
    }
}
